home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / abbrev5.zip / ABLOOKUP.M < prev    next >
Text File  |  1990-01-22  |  5KB  |  132 lines

  1. ;**************************************************************************
  2. ;*                                                                                                  *
  3. ;*     ABLOOKUP.CB                                                                              *
  4. ;*                                                                                               *
  5. ;*     This contains the utility files used both by "abbrev" and              *
  6. ;*     "suffix".  Either package may be used alone in conjunction              *
  7. ;*     with this file, and suffix no longer requires the full                  *
  8. ;*     abbrev to be used.                                                                  *
  9. ;*                                                                                               *
  10. ;*     Larry DeMar   10-19-89.                                                              *
  11. ;*                                                                                                  *
  12. ;**************************************************************************
  13. ;*                                                                                                  *
  14. ;*      AB_LOOKUP                                                                              *
  15. ;*                                                                                               *
  16. ;*      This is called to look up a string in an abbreviation file.          *
  17. ;*                                                                                               *
  18. ;*      Parameter 0 = file part of file name to look in                          *
  19. ;*      Parameter 1 = string to lookup                                                  *
  20. ;*      Parameter 2 = global buffer id of system buffer we're using          *
  21. ;*      Parameter 3 = filename for system buffer                                      *
  22. ;*                                                                                               *
  23. ;*      If parameter 2 is non-zero, then it is the id of a                      *
  24. ;*      system buffer containing the lookup file.  Else, we                      *
  25. ;*      create the system buffer.  Read the lookup file in,                      *
  26. ;*      and put the new buffer id to parameter 2.                                  *
  27. ;*                                                                                               *
  28. ;*      If the string is found to start in column 1 of the                      *
  29. ;*      lookup file, then the "return string" is on the                          *
  30. ;*      rest of the line in the file.    The return string                          *
  31. ;*      is put back to parameter 1.                                                      *
  32. ;*                                                                                               *
  33. ;*      This returns TRUE of FALSE based on whether the lookup                  *
  34. ;*      succeeded.                                                                              *
  35. ;*                                                                                                  *
  36. ;**************************************************************************
  37. (macro ab_lookup
  38.    (
  39.       (string file_part
  40.               abbreviation
  41.               my_search_string
  42.               sys_file_name
  43.       )
  44.       (int orig_buffer
  45.            system_id
  46.            return_code
  47.       )
  48.       (set_msg_level 1)
  49.       (get_parm 0 file_part)
  50.       (get_parm 1 abbreviation)
  51.       (get_parm 2 system_id)
  52.       (get_parm 3 sys_file_name)
  53.       (= orig_buffer (inq_buffer))
  54.       (if system_id          ; abbrev file in buffer?
  55.          (set_buffer system_id)    ; yep...go there
  56.       ;else
  57.          (
  58.             (= system_id (create_sys_buf file_part sys_file_name))   ; no...create it.
  59.             (put_parm 2 system_id)      ; and pass it back.
  60.          )
  61.       )
  62.       (top_of_buffer)
  63.       (sprintf my_search_string "<%s[ \t]\\c" abbreviation)
  64.       (if (= return_code (search_fwd my_search_string 1 0))
  65.          (put_parm 1 (trim (ltrim (read))))
  66.       )
  67.       (set_buffer orig_buffer)
  68.       (return return_code)
  69.    )
  70. )
  71. ;**************************************************************************
  72. ;*                                                                                                  *
  73. ;*      CREATE_SYS_BUF                                                                      *
  74. ;*                                                                                               *
  75. ;*      This is called to create the system buffer and read in                  *
  76. ;*      the abbreviation file.                                                              *
  77. ;*                                                                                               *
  78. ;*      It returns the id of the buffer it creates.                                  *
  79. ;*                                                                                                  *
  80. ;**************************************************************************
  81. (macro create_sys_buf
  82.    (
  83.       (int buf_id)
  84.       (string file_part
  85.               buffer_name
  86.       )
  87.       (get_parm 0 file_part)
  88.       (get_parm 1 buffer_name)
  89.       (= buf_id (create_buffer "abbrev_buf" buffer_name 1))
  90.       (set_buffer buf_id)
  91.       (if (exist (= file_part (get_abbrev_file file_part)))
  92.          (read_file file_part)   ; read in the file
  93.       )
  94.       (return buf_id)
  95.    )
  96. )
  97. ;**************************************************************************
  98. ;*                                                                                                  *
  99. ;*      GET_ABBREV_FILE                                                                      *
  100. ;*                                                                                               *
  101. ;*      This is called to return the full path of the abbrev                      *
  102. ;*      directory file.                                                                      *
  103. ;*                                                                                               *
  104. ;*              1) if BABBREV is in environment, then it is                          *
  105. ;*                  used as the path.                                                      *
  106. ;*                                                                                               *
  107. ;*              2) if BPATH is in environment, then it is                          *
  108. ;*                  used as the path.                                                      *
  109. ;*                                                                                               *
  110. ;*              3) otherwise "C:\" is used as the path.                              *
  111. ;*                                                                                                  *
  112. ;**************************************************************************
  113. (macro get_abbrev_file
  114.    (
  115.       (string abbrev_path
  116.               file_part
  117.       )
  118.       (int semi_spot)
  119.       (get_parm 0 file_part)
  120.       (if (== (= abbrev_path (inq_environment "BABBREV")) "")
  121.          (if (== (= abbrev_path (inq_environment "BPATH")) "")
  122.             (= abbrev_path "c:")
  123.          ;else
  124.             (if (= semi_spot (rindex abbrev_path ";"))
  125.                (= abbrev_path (substr abbrev_path (+ semi_spot 1)))
  126.             )
  127.          )
  128.       )
  129.       (return (+ (trim (ltrim abbrev_path)) (+ "\\" file_part)))
  130.    )
  131. )
  132.